package originala;

import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Random;

public class ZorizkoZenbakia extends UnicastRemoteObject implements ZorizkoZenbakiaInterfazea {
     private static final Remote ZorizkoZenbakia = null;
	private Random balioa;
	
	public ZorizkoZenbakia() throws RemoteException{
	
	this.balioa=new Random();
		
		
	}
	public int balioaLortu(int i){
		return balioa.nextInt(i);
	}
	public static void main(String[] args) throws RemoteException, MalformedURLException 
    {System.setProperty("java.security.policy","java.policy");
	System.setSecurityManager(new RMISecurityManager());
	
	try{
	ZorizkoZenbakia ZorizkoZenbakia= new ZorizkoZenbakia();
	System.out.println("objektua jaurtia");
	try { 
	
	java.rmi.registry.LocateRegistry.createRegistry(1099); // RMIREGISTRY jaurtitzearen baliokidea

    }
	catch (Exception e) {
		System.out.println(e.toString()+"\nSuposatzen dugu errorea dela rmiregistry aurretik jaurti delako ");
		}

	String zorizkozenbakia="//localhost/zorizkozenbakia";
	Naming.rebind(zorizkozenbakia, ZorizkoZenbakia);
	
  }

	
	catch (Exception e) {
	System.out.println(e.toString()+"\nSuposatzen dugu errorea dela rmiregistry aurretik jaurti delako ");
	}

	
    }
	public int balioaLortu() throws RemoteException {
		return 0;
	}
	    
}
